#include "CDaySignCfg.h"
#include "commerrno.h"
#include "../mainctrl.h"

int CDaySignCfg::CheckDaySignCfg()
{
    for (int i = 0; i < GetContinueDataSize(); ++i)
    {
        CKeyValue& stKeyValue = GetContinueData(i);

        //要求签到次数是递增的 可以是[0,7]
        if (stKeyValue._iValue < 0 ||
            stKeyValue._iValue > MAX_DAY_SIGN_CONTINUE_TIMES)
        {
            return ERROR_DAY_SIGN_CONFIG_DATA;
        }

        if (i - 1 >= 0)
        {
            CKeyValue& stKeyTemp = GetContinueData(i - 1);
            if (stKeyTemp._iValue >= stKeyValue._iValue)
            {
                return ERROR_DAY_SIGN_CONFIG_DATA;
            }
        }
        
        //校验连续签到礼包ID的存在性 
        if (!CMainCtrl::m_pstMain->m_stItemMgr.IsGiftValid(stKeyValue._uiKey))
        {
            CT_RETURN(ERROR_GIFT_CONFIG_NONE);
        }
    }


    for (int i = 0; i < GetAccumulateDataSize(); ++i)
    {
        CKeyValue& stKeyValue = GetAccumulateData(i);

        //要求签到次数是递增的 可以是[0,31]
        if (stKeyValue._iValue < 0 ||
            stKeyValue._iValue > MAX_DAY_SIGN_ACCUMULATE_TIMES)
        {
            return ERROR_DAY_SIGN_CONFIG_DATA;
        }

        if (i - 1 >= 0)
        {
            CKeyValue& stKeyTemp = GetAccumulateData(i - 1);
            if (stKeyTemp._iValue >= stKeyValue._iValue)
            {
                return ERROR_DAY_SIGN_CONFIG_DATA;
            }
        }
        
        //校验累计签到礼包ID的存在性 
        if (!CMainCtrl::m_pstMain->m_stItemMgr.IsGiftValid(stKeyValue._uiKey))
        {
            CT_RETURN(ERROR_GIFT_CONFIG_NONE);
        }
    }

    return 0;
}

